﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Supervise_BefGoodsList : System.Web.UI.Page
{
    public string name, medicinemodel, outlookc, strConditions;
    public string show;
    protected void Page_Load(object sender, EventArgs e)
    {


        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {

            if (!IsPostBack)
            {
                txtname.Text = "";
                txtmedicinemodel.Text = "";
                txtoutlook.Text = "";


                List_memo1.Items.Add("全部");
                List_memo1.Items.Add("非医保");
                List_memo1.Items.Add("医保");
                //chk1.Visible = false;
            }

            showGridView();
        }
    }

    protected void Button5_Click(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 查询总共有多少页
    /// </summary>
    /// <returns></returns>
    /// <summary>
    /// 将数据绑定到GridView1
    /// </summary>
    /// <param name="PageIndex">转向第几页</param>
    public void showGridView()
    {

        string _SelectField = "GoodsByCompanyid as goodsid,case GoodsByCompany.IsSendin when 1 then '已递交' else '未递交' end as IsSendin,productname,GoodsName,medicinemodel,outlookc,Unit,xishu,AccountName_SH,shenhetime,NoPass,case GoodsByCompany.CheckStatus when '1' then '审核通过' when '2' then '审核未通过' when '3' then '纸质材料一致' else '未审核' end as CheckStatus, case GoodsByCompany.memo1 when '0' then '非医保' when '1' then '医保' end as memo1,PackUnit,companyName,AccountName as AccountName_TJR,dbo.Chk_GetCompanyName(AccountId_TJR) as companyname_trj,case QualityLevels " + ConfigurationManager.AppSettings["QualityLevels"].ToString() + " end as QualityLevels";

        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "  GoodsByCompany left JOIN company ON GoodsByCompany.AccountId_Sc = company.AccountId inner join Account on GoodsByCompany.AccountId_TJR=Account.AccountId ";                                               //要查询的表明
        dbPage.Key = "GoodsByCompanyid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = _SelectField;//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = Convert.ToInt32(Lpagenum.SelectedItem.Value);                                                    //没有显示记录条数   
        dbPage.OrderBy = "GoodsByCompanyid,productname,medicinemodel,outlookc";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        dr = null;
        db = null;
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键



    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp = "";

        string _memo1 = List_memo1.Text.ToString();

        switch (_memo1)
        {
            case "全部":
                break;
            case "非医保":
                strtemp += " GoodsByCompany.memo1='0' and";
                break;
            case "医保":
                strtemp += " GoodsByCompany.memo1='1' and";
                break;

        }
        //审核状态
        if (List_memo3.SelectedValue != "4")
        {
            strtemp += " isnull(GoodsByCompany.CheckStatus,0)='" + List_memo3.SelectedValue + "' and";
        }
        //审核人
        if (txtSHR.Text.Trim() != "")
        {
            strtemp += " AccountName_SH like '%" + txtSHR.Text.Trim() + "%' and";
        }
        //流水号
        string stgoods = txtgoods.Text.ToString().Trim();
        if (stgoods != "")
        {
            strtemp = strtemp + "  GoodsByCompanyid ='" + stgoods + "' and";
        }

        //通用名

        string name = txtname.Text.ToString().Trim();
        if (name != "")
        {
            strtemp = strtemp + "  ProductName like '%" + name + "%' and";
        }
        //剂型
        string medicinemodel = txtmedicinemodel.Text.ToString().Trim();
        if (medicinemodel != "")
        {
            strtemp = strtemp + " medicinemodel like '%" + medicinemodel + "%' and";
        }
        //规格
        string outlookc = txtoutlook.Text.ToString().Trim();
        if (outlookc != "")
        {
            strtemp = strtemp + " outlookc like '%" + outlookc + "%' and";
        }
        //商品名

        string strgoodsname = txtGoodsName.Text.ToString().Trim();
        if (strgoodsname != "")
        {
            strtemp = strtemp + " goodsname like '%" + strgoodsname + "%' and";
        }
        //添加人名称  或注册号
        string companyname = txtCompanyName.Text.ToString().Trim();
        if (companyname != "")
        {
            strtemp = strtemp + " (dbo.Chk_GetCompanyName(AccountId_TJR) like '%" + companyname + "%' or AccountName like '%" + companyname + "%') and";
        }
        //单位
        string strunit = TextUnit.Text.ToString().Trim();
        if (strunit != "")
        {
            strtemp += " unit like '%" + strunit + "%'  and";
        }
        ////企业注册号

        //string strCM = txtCompanyNum.Text.ToString().Trim();
        //if (strCM != "")
        //{
        //    strtemp += " Usercode like'%" + strCM + "%' and";
        //}
        //转换系数
        String strXS = txtZhuanhuan.Text.ToString().Trim();
        if (strXS != "")
        {
            strtemp += " xishu = '" + strXS + "' and";

        }
        //是否递交
        switch (LIsSendin.SelectedIndex)
        {
            case 0:// 未递交 
                strtemp += " isnull(GoodsByCompany.IsSendin,0)=0 and";
                break;
            case 1: //已递交
                strtemp += " isnull(GoodsByCompany.IsSendin,0)=1 and";
                break;
            case 2:   //全部

                break;

        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }

        return strtemp;

    }
    public string fctConditions2()
    {
        string strtemp = "";


        //流水号
        string stgoods = txtgoods.Text.ToString().Trim();
        if (stgoods != "")
        {
            strtemp = strtemp + "  a.GoodsByCompanyid ='" + stgoods + "' and";
        }

        //通用名
        string name = txtname.Text.ToString().Trim();
        if (name != "")
        {
            strtemp = strtemp + "  a.ProductName like '%" + name + "%' and";
        }
        //剂型
        string medicinemodel = txtmedicinemodel.Text.ToString().Trim();
        if (medicinemodel != "")
        {
            strtemp = strtemp + " a.medicinemodel like '%" + medicinemodel + "%' and";
        }
        //规格
        string outlookc = txtoutlook.Text.ToString().Trim();
        if (outlookc != "")
        {
            strtemp = strtemp + " a.outlookc like '%" + outlookc + "%' and";
        }
        //商品名

        string strgoodsname = txtGoodsName.Text.ToString().Trim();
        if (strgoodsname != "")
        {
            strtemp = strtemp + " a.goodsname like '%" + strgoodsname + "%' and";
        }
        //生产企业名称
        string companyname = txtCompanyName.Text.ToString().Trim();
        if (companyname != "")
        {
            strtemp = strtemp + " a.companyName like '%" + companyname + "%' and";
        }
        //单位
        string strunit = TextUnit.Text.ToString().Trim();
        if (strunit != "")
        {
            strtemp += " a.unit like '%" + strunit + "%'  and";
        }
        ////企业注册号

        //string strCM = txtCompanyNum.Text.ToString().Trim();
        //if (strCM != "")
        //{
        //    strtemp += " a.Usercode like'%" + strCM + "%' and";
        //}

        //转换系数
        String strXS = txtZhuanhuan.Text.ToString().Trim();
        if (strXS != "")
        {
            strtemp += " a.xishu = '" + strXS + "' and";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }

        return strtemp;

    }
   

    #region IPageDescribe 成员

    public string Name
    {
        get { return "审核商品信息"; }
    }

    public string Describe
    {
        get { return "审核商品信息"; }
    }

    public string ParentName
    {
        get { return "商品维护"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumSupervise);
            return _AccountType;
        }
    }
    #endregion


    // 确认递交
    protected void Button6_Click(object sender, EventArgs e)
    {
        Updateissendin(1);
    }
    //取消递交
    protected void Button7_Click(object sender, EventArgs e)
    {
        Updateissendin(0);
    }

    private void Updateissendin(int _issendin)
    {
        string _strgoods = "";
        if (Request.Form["chk"] != null && Request.Form["chk"].ToString() != "")
        {
            _strgoods = Request.Form["chk"].ToString();
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            HZ.MBSM.BLL.Goods good = new HZ.MBSM.BLL.Goods();
            if (good.UpdateIssendin(_strgoods, _Account.AccountId.ToString(), _issendin, 1))
            {
                Response.Write("<script>alert('提交成功！！！');</script>");
            }
            else
            {
                Response.Write("<script>alert('提交失败！！！');</script>");
            }
        }
        else
        {
            Response.Write("<script>alert('请选择商品！！！');</script>");
        }
        showGridView();
    }
}
